import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../../basic/base_info.dart';
import '../../config/const.dart';
import '../../widget/common_widget.dart';
import '../home/home.dart';
import '../login/login.dart';

class MinSettingPage extends StatefulWidget {
  const MinSettingPage({super.key});

  @override
  State<MinSettingPage> createState() => _MinSettingPageState();
}

class _MinSettingPageState extends State<MinSettingPage> {

  List items = [
    // {
    //   'img':'assets/home/min_product.png',
    //   'name':'Reset Password'.tr,
    //   'value':''
    // },
    {
      'img':'assets/home/min_product.png',
      'name':'Security'.tr,
      'value':'',
      'isShow':true,
    },
    {
      'img':'assets/home/min_product.png',
      'name':'Set The language'.tr,
      'value':'',
      'isShow':false,
    },
    {
      'img':'assets/home/min_product.png',
      'name':'Manage Access'.tr,
      'value':'',
      'isShow':true,
    },
    {
      'img':'assets/home/min_product.png',
      'name':'Off-Grid Mode'.tr,
      'value':'',
      'isShow':false,
    },
    {
      'img':'assets/home/min_product.png',
      'name':'AI Guard'.tr,
      'value':'',
      'isShow':true,
    },
    {
      'img':'assets/home/min_product.png',
      'name':'Message Notifications'.tr,
      'value':'',
      'isShow':false,
    },
    {
      'img':'assets/home/min_product.png',
      'name':'Clear Cache'.tr,
      'value':'',
      'isShow':false,
    },
  ];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: defaultBlackBgColor,
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 48.w),
        child: Column(
          children: [
            SizedBox(height: ScreenUtil().statusBarHeight + 40.w,),
            myCustomCenterTitleAppBar('Setting'),
            SizedBox(height: 40.w,),
            Expanded(child: Container(
              child: SingleChildScrollView(
                child: Container(
                  padding: EdgeInsets.symmetric(horizontal: 40.w),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(16.w),
                      color: Color(0xff1e1d20)
                  ),
                  child: ListView.builder(itemBuilder: (ctx,index){
                    Map item = items[index];
                    if(!item['isShow']){
                      return Container();
                    }
                    if(index == 2 && grade != null && grade!['userGrade'] != null && grade!['userGrade'].toString() != '1'){
                      return Container();
                    }
                    return GestureDetector(
                      onTap: () {
                        if(index == 0){
                          Navigator.of(context).pushNamed('MinSettingSecurityPage');
                        }else if(index == 1){
                          Navigator.of(context).pushNamed('MinSetLanguagePage');
                        }else if(index == 2){
                          Navigator.of(context).pushNamed('MinManageAccessPage',arguments: grade);
                        }else if(index == 4){
                          Navigator.of(context).pushNamed('MinAiGuardPage');
                        }else if(index == 3){
                          Navigator.of(context).pushNamed('SeasonsScreen');
                        }
                      },
                      child: Container(
                        height: 120.w,
                        child: Column(
                          children: [
                            Expanded(child: Container(
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: [
                                  // Image.asset(item['img'],width: 40.w,),
                                  // SizedBox(width: 8.w,),
                                  Expanded(child: Text(item['name'],style: TextStyle(
                                      color: Colors.white,
                                      fontWeight: FontWeight.w600,
                                      fontSize: 28.sp
                                  ),)),
                                  SizedBox(width: 24.w,),
                                  // Container(
                                  //   child: Text(item['value'],style: TextStyle(
                                  //     color: Color.fromRGBO(255, 255, 255, 0.5),
                                  //     fontSize: 24.sp,
                                  //     fontWeight: FontWeight.w400
                                  //   ),),
                                  // ),
                                  SizedBox(width: 0.w,),
                                  Image.asset('assets/common/control_right.png',width: 48.w,),
                                ],
                              ),
                            )),
                            Visibility(child: Container(
                              height: 1.w,
                              color: Color.fromRGBO(255, 255, 255, 0.1),
                            ),visible: index != item.length-1,),
                          ],
                        ),
                      ),
                    );
                  },padding: EdgeInsets.zero,shrinkWrap: true,physics: NeverScrollableScrollPhysics(),itemCount: items.length,),
                ),
              ),
            )),
            SizedBox(height: 32.w,),
            GestureDetector(
              onTap: (){
                LocalBaseInfo.clearInfo();
                Navigator.pushAndRemoveUntil(context, PageRouteBuilder(
                    settings: const RouteSettings(name: "login"),
                    pageBuilder:
                        (BuildContext context, Animation animation,
                        Animation secondaryAnimation) {
                      return const LoginPage();
                    }), (route) => false);
              },
              child: Container(
                child: Text('Log Out'.tr,style: TextStyle(
                    color: Colors.white,
                    fontSize: 32.sp,
                  fontWeight: FontWeight.w600
                ),),
                decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(8.w),
                    color: Color.fromRGBO(255, 255, 255, 0.1)
                ),
                height: 108.w,
                alignment: Alignment.center,
              ),
            ),
            SizedBox(height: ScreenUtil().bottomBarHeight+10.w,)
          ],
        ),
      ),
    );
  }

}
